//
//  AuthorizationView.m
//  LoansPresident
//
//  Created by fh on 2018/12/4.
//  Copyright © 2018年 fh. All rights reserved.
//

#import "AuthorizationView.h"

@interface AuthorizationView ()
@property (nonatomic, strong) UIButton *openSettingButton;
@end

@implementation AuthorizationView
- (instancetype)init {
    if (self = [super init]) {
        [self addSubview:self.authorizationInfoLabel];
        [self addSubview:self.openSettingButton];
        [self addSubview:self.cancleButton];
        [self.authorizationInfoLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(40));
            make.right.equalTo(@(-40));
            make.top.equalTo(@(0));
        }];
        [self.cancleButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.authorizationInfoLabel.mas_left);
            make.top.equalTo(self.authorizationInfoLabel.mas_bottom).offset(60);
            make.bottom.equalTo(@(0));
            make.height.equalTo(@(40));
//            make.width.equalTo(self.mas_width).multipliedBy(0.5);
            make.width.equalTo(@(60));
        }];
        [self.openSettingButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.authorizationInfoLabel.mas_right);
            make.top.equalTo(self.cancleButton.mas_top);
            make.bottom.equalTo(self.cancleButton.mas_bottom);
            make.height.equalTo(self.cancleButton.mas_height);
            make.width.equalTo(@(100));
        }];
    }
    return self;
}
#pragma mark - Event
- (void)openSettingButtonAction:(UIButton *)button {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
#pragma mark - Setter and getter
- (UIButton *)openSettingButton {
    if (!_openSettingButton) {
        _openSettingButton = [UIButton new];
        [_openSettingButton setTitle:@"开启设置" forState:UIControlStateNormal];
        _openSettingButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [_openSettingButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // [UIColor waveColor]
        [_openSettingButton addTarget:self action:@selector(openSettingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        _openSettingButton.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        _openSettingButton.backgroundColor = [UIColor orangeColor];
        _openSettingButton.layer.cornerRadius = 3;
    }
    return _openSettingButton;
}
- (UIButton *)cancleButton {
    if (!_cancleButton) {
        _cancleButton = [UIButton new];
        [_cancleButton setTitle:@"取消" forState:UIControlStateNormal];
        _cancleButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [_cancleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // [UIColor indianRedColor]
        _cancleButton.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        _cancleButton.layer.cornerRadius = 3;
    }
    return _cancleButton;
}
- (UILabel *)authorizationInfoLabel {
    if (!_authorizationInfoLabel) {
        _authorizationInfoLabel = [UILabel new];
        _authorizationInfoLabel.textColor = [UIColor blackColor];
        _authorizationInfoLabel.font = [UIFont boldSystemFontOfSize:16];
        _authorizationInfoLabel.numberOfLines = 0;
        _authorizationInfoLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _authorizationInfoLabel;
}
@end
